package com.qcsec.controller.system;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.mybatisflex.core.paginate.Page;
import com.qcsec.common.base.RestResp;
import com.qcsec.domain.entity.SysMenu;
import com.qcsec.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@ApiSort(value = 3)
@Slf4j
@Api(tags = "系统管理-菜单")
@RequestMapping("/test/system/menu")
@RestController
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;
    @ApiOperationSupport(order = 1)
//    @ApiImplicitParam(value = "搜索条件", name = "SysMenuReq", dataType = "SysMenuReq", dataTypeClass = SysMenuReq.class)
    @ApiOperation("分页查询")
    @GetMapping("/getPage")
    public RestResp<Page<SysMenu>> getPage(SysMenu req){
        Page<SysMenu> page = sysMenuService.getPage(req);
        return RestResp.ok(page);
    }
    @ApiOperationSupport(order = 2)
//    @ApiImplicitParam(value = "ID", name = "menuId", dataType = "Long", dataTypeClass = Long.class)
    @ApiOperation("根据ID查询")
    @GetMapping("/getById")
    public RestResp<SysMenu> getById(Long menuId){
        SysMenu resp = sysMenuService.getById(menuId);
        return RestResp.ok(resp);
    }
    @ApiOperationSupport(order = 3)
//    @ApiImplicitParam(value = "搜索条件", name = "SysMenu", dataType = "SysMenu", dataTypeClass = SysMenu.class)
    @ApiOperation("查询所有")
    @GetMapping("/getAll")
    public RestResp<List<SysMenu>> getAll(SysMenu menu){
        List<SysMenu> roles = sysMenuService.getAll(menu);
        return RestResp.ok(roles);
    }
    @ApiOperationSupport(order = 4)
//    @ApiImplicitParam(value = "模型信息（ID不存在）", name = "SysMenu", dataType = "SysMenu", dataTypeClass = SysMenu.class)
    @ApiOperation("保存")
    @PostMapping("/save")
    public RestResp<?> save(@RequestBody SysMenu menu){
        boolean i = sysMenuService.saveAndEdit(menu);
        return i ? RestResp.ok() : RestResp.fail();
    }
    @ApiOperationSupport(order = 5)
//    @ApiImplicitParam(value = "信息（ID存在）", name = "SysMenu", dataType = "SysMenu", dataTypeClass = SysMenu.class)
    @ApiOperation("编辑")
    @PutMapping("/edit")
    public RestResp<?> edit(@RequestBody SysMenu menu){
        boolean i = sysMenuService.saveAndEdit(menu);
        return i ? RestResp.ok() : RestResp.fail();
    }
    @ApiOperationSupport(order = 6)
//    @ApiImplicitParam(value = "id集合", name = "ids", dataType = "List<Long>", dataTypeClass = List.class)
    @ApiOperation("删除")
    @PostMapping("/deleteByIds")
    public RestResp<?> deleteByIds(@RequestBody List<Long> ids){
        boolean i = sysMenuService.deleteByIds(ids);
        return i ? RestResp.ok() : RestResp.fail("参数不能为空");
    }
}
